package com.jzr.medical.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jzr.common.entity.vo.Result;
import com.jzr.common.entity.vo.ResultPage;
import com.jzr.common.util.QueryUtil;
import com.jzr.common.util.U;
import com.jzr.medical.db1.dto.BedDto;
import com.jzr.medical.db1.service.BedService;
import com.jzr.medical.db1.service.DeviceService;
import com.jzr.medical.db1.vo.BedRefVo;
import com.jzr.medical.db1.vo.BedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/bed")
public class BedController {
    @Autowired
    private BedService bedService;

    @Autowired
    private DeviceService deviceService;

    @PostMapping("/list")
    public ResultPage<BedVo> list(@RequestBody BedDto record) {
        QueryWrapper<BedVo> qw = new QueryWrapper<>();
        QueryUtil.orderBy(qw,record.getOrderByClause());
        qw.eq(U.isNotBlank(record.getDeptCode()),BedVo.DeptCode_,record.getDeptCode())
                .eq(U.isNotBlank(record.getBedCode()),BedVo.BedCode_,record.getBedCode());
        IPage<BedVo> page = new Page<>(record.getPageNum(),record.getPageSize());
        List<BedVo> list = bedService.list(page,qw);
        page.setRecords(list);
        return ResultPage.success("成功",page);
    }

    @GetMapping("/getRefList")
    public Result<List<BedRefVo>> getRefList(String deptCode){
        List<BedRefVo> list = bedService.getRefList(deptCode);
        return Result.success("成功",list);
    }

    @PostMapping("/saveBatch")
    public Result<List<BedVo>> saveBatch(@RequestBody List<BedVo> list){
        List<BedVo>  result = bedService.saveBatch(list);
        return Result.success("成功",result);
    }

}
